<template>
  <div class="center">
    <el-row class="row-b10">
      <el-col :lg="6" :sm="12" :xs="12">
        <el-input v-model="before" placeholder="请输入前区号" class="input-with-select game_select" />
      </el-col>
      <el-col :lg="6" :sm="12" :xs="12">
        <el-input v-model="after" placeholder="请输入后区号" class="input-with-select game_select" />
      </el-col>
      <el-col :lg="6" :sm="12" :xs="12">
        <el-select
          class="_sel"
          v-model="gameNo"
          placeholder="请选择游戏"
          style="width: 100%"
        >
          <el-option label="双色球" value="1" />
          <el-option label="大乐透" value="2" />
        </el-select>
      </el-col>
      <el-button type="primary" icon="el-icon-search" @click="queryNumber(before, after)" />
    </el-row>
    <!-- 搜索和搜索历史记录 -->
    <el-row>
      <el-col :span="24" class="mb20">
        <ul class="ul">
          <li v-for="(item,index) in log" :key="index" class="li">
            <span>{{ item }}</span>
            <i class="el-icon-circle-close" @click="removeLog(index)"></i>
          </li>
        </ul>
      </el-col>
    </el-row>
    <el-table
      :data="result"
      :header-cell-style="{'text-align': 'center','padding': '5px 0'}"
      :cell-style="{'text-align':'center','padding': '5px 0'}"
      style="width: 100%">
      <el-table-column
        prop="code"
        label="期号">
      </el-table-column>
      <el-table-column
        label="开奖号码">
        <template slot-scope="scope">
          <div style="color: dodgerblue;cursor: pointer;">{{scope.row.redBlue}}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="zjCode"
        label="中了"
      >
        <template slot-scope="{row}">
          <div v-html="row.zjCode" />
        </template>
      </el-table-column>
      <el-table-column
        prop="date"
        label="开奖日期"
      ></el-table-column>
    </el-table>
  </div>
</template>
<script>
import axios from 'axios';
import {ssq} from './ssq'
export default {
  name: 'pair-color-lotto',
  data() {
    return {
      gameNo: '1',
      log: [],
      result: [],
      before: '',
      after: ''
      // len: 10
    }
  },
  mounted() {
    if (localStorage.getItem('pair-lotto')) {
      this.log = JSON.parse(localStorage.getItem('pair-lotto'))
    }
    this.initData()
  },
  watch: {
    gameNo(val) {
      if (val === '1') {
        this.ssq()
      } else if (val === '2') {
        this.dlt()
      }
    }
  },
  methods: {
    initData() {
      this.ssq()
    },
    dlt() {
      axios.get(`https://webapi.sporttery.cn/gateway/lottery/getHistoryPageListV1.qry?gameNo=85&provinceId=0&pageSize=100&isVerify=1&pageNo=1`).then(res => {
        if (res.data.success) {
          this.result = res.data.value.list.map(item => ({
            ...item,
            code: item.lotteryDrawNum,
            date: item.lotteryDrawTime,
            redBlue: item.lotteryDrawResult,
            before: item.lotteryDrawResult.split(' ').splice(0, 5),
            after: item.lotteryDrawResult.split(' ').splice(5),
            zjCode: ''
          }))
        }
      })
    },
    ssq() {
    //  axios({
    //     method: 'get',
    //     url: 'https://www.cwl.gov.cn/api1/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&issueCount=&issueStart=&issueEnd=&dayStart=&dayEnd=&pageNo=1&pageSize=30&week=&systemType=PC'
    //   }).then(res => {
    //     this.result = res.data.result.map(item => ({
    //       ...item,
    //       redBlue: `${item.red.replace(/,/g,' ')} ${item.blue}`,
    //       before: item.red.split(','),
    //       after: item.blue.split(','),
    //       zjCode: ''
    //     }))
    //   })
      let res = ssq()
      // res.result.length = 10
      this.result = res.result.map(item => ({
        ...item,
        redBlue: `${item.red.replace(/,/g,' ')} ${item.blue}`,
        before: item.red.split(','),
        after: item.blue.split(','),
        zjCode: ''
      }))
    },
    queryNumber(before, after) {
      const beSet = new Set(before.split(' '));
      const afSet = new Set(after.split(' '));

      for (const item of this.result) {
        const zjCodeSet = [];
        
        // 检查 before 数组
        for (const val of item.before) {
          if (beSet.has(val)) zjCodeSet.push(val);
        }
        
        // 检查 after 数组
        for (const val of item.after) {
          if (afSet.has(val)) zjCodeSet.push(`<span style="color: red;">${val}</span>`);
        }
        
        item.zjCode = Array.from(zjCodeSet).join(',');
      }
    },
    removeLog(index) {
      this.log.splice(index,1)
      localStorage.setItem('pair-lotto',JSON.stringify(this.log))
    },
  }
}
</script>
<style lang="scss" scoped>
.center{
  max-width: 1200px;
  width: 100%;
  margin: 20px auto 0;
}
.col {
  display: flex;
  flex-direction: column;
  text-align: center;
  align-items: center;
  span {
    display: flex;
    // width: 30px;
    // height: 30px;
    border-radius: 15px;
    // background: #f00;
    // margin: 10px 0;
    // line-height: 30px;
    margin-top: 10px;
    color: #f00;
    justify-content: center;
    align-items: center;
  }
}
.el-row {
  justify-content: center;
  .el-col {
    padding: 0 5px;
    &:nth-child(7) {
      span {
        // background: #00f;
        color: #00f;
      }
    }
  }
}
.border-lr{
  padding: 0 5px;
  border-left: 1px solid red;
  border-right: 1px solid red;
  margin-right: 5px;
}
/deep/.radio0{
  border-radius: 0;
  .el-input__inner{
    border-radius: 0;
    height: 35px;
    line-height: 30px;
    text-align: center;
    padding: 0;
  }
  &.inp{
    .el-input__inner{
      border-top: 0;
      border-right: 0;
      border-left: 0;
      border-bottom: 1px solid rgb(0, 157, 255);
      padding: 0;
      background: transparent;
      width: 100%;
    }
  }
  &.inp{
    border-top: 0;
    border-right: 0;
    border-left: 0;
    border-bottom: 1px solid rgb(0, 157, 255);
    padding: 0;
    background: transparent;
    width: 100%;
    text-align: center;
    height: 35px;
    outline: none;
    font-size: 15px;
  }
}
.ul{
  padding: 0;
  margin: 0;
  .li{
    list-style-type: none;
    display: inline-block;
    margin-right: 12px;
    padding: 10px 0;
    color: #666;
    letter-spacing: .5px;
    font-size: 14px;
    i{
      margin-left: 7px;
      color: #F56C6C;
      cursor: pointer;
      -webkit-tap-highlight-color:transparent
    }
    span{
      cursor: pointer;
      -webkit-tap-highlight-color:transparent
    }
  }
}
/deep/.game_select{
  .el-input-group__prepend{
    width: 125px;
    padding: 0;
    .el-select{
      margin: -1px;
    }
  }
}
</style>